package main

import (
	"fmt"
	"regexp"
	"time"
)

// 性能优化：预编译正则表达式
var (
	pattern = `^(?:[a-z0-9!#$%&'*+/=?^_` + "`" + `{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_` + "`" + `{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\[IPv6:[0-9a-fA-F]{1,4}(?::[0-9a-fA-F]{1,4}){7}\])\])$`
	re      = regexp.MustCompile(pattern)
)

func main() {
	start := time.Now()
	duration := time.Since(start)
	fmt.Printf("Regex compiled in %s\n", duration)

	// 使用正则表达式
	testStr := "example@example.com"
	fmt.Println("Match:", re.MatchString(testStr))
	fmt.Printf("end in %s\n", time.Since(start))
}
